/*
 * @Descripttion:
 * @version:
 * @Author: kl2018
 * @Date: 2020-05-22 16:59:22
 * @LastEditors: kl2018
 * @LastEditTime: 2020-08-18 10:26:42
 */
import React from 'react';
import { observer, inject, Provider } from 'mobx-react';
import { Button } from 'antd';
import { WeaDialog, WeaLocaleProvider, WeaTools, WeaErrorPage } from 'ecCom';
import DocMoulePublicComp from './DocMoulePublicComp';
import stores from '../../../stores';

const { getLocaleLabelByCode, getLabel } = WeaLocaleProvider;
@inject('docTemplateStore')
@observer
class DocTemplate extends React.Component {
  constructor(props) {
    super(props);
  }

  componentDidMount() {
    const { workflowid, requestid, docid, imagefileId, yozoView, wpsView } = WfForm.getOdocConfig().docParam;
    const { getMouldList, doInitParams } = this.props.docTemplateStore;
    doInitParams(workflowid, requestid, docid, imagefileId, yozoView, wpsView);// 初始化参数
    getMouldList();// 获取套红列表
  }

  render() {
    const { removeDialog, confirmTh, fullView = 0, visible } = this.props.docTemplateStore;
    let buttons = [
      <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@3i3ilj@ok`} type="primary" onClick={confirmTh}>{getLabel('826', '确定')}</Button>,
      <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@su0iup@cancel`} onClick={removeDialog}>{getLabel('31129', '取消')}</Button>,
    ];
    if (fullView == 1) {
      buttons = [
        <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@u427ul@close`} type="primary" onClick={removeDialog}>{getLabel('309', '关闭')}</Button>,
      ];
    }
    return (
      <div className={'doc-template'}>
        <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@arx5zt`}
          onCancel={removeDialog}
          title={fullView == 0 ? getLabel('25125', '套红模板选择') : '套红预览'}
          visible={visible}
          style={{ width: 1100, height: 600 }}
          buttons={buttons}
          scalable={true}
          hasScroll
          draggable={false}
          icon={'icon-coms-official'}
          iconBgcolor="red"
        >
          <DocMoulePublicComp ecId={`${this && this.props && this.props.ecId || ''}_DocMoulePublicComp@fg9qis`} />
        </WeaDialog>
      </div>
    );
  }
}
// export default Index;

class MyErrorHandler extends React.Component {
  render() {
    const hasErrorMsg = this.props.error && this.props.error !== '';
    return (
      <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@jjiouh`} msg={hasErrorMsg ? this.props.error : `${getLabel(385218, '对不起，该页面异常，请联系管理员！')}`} />
    );
  }
}

class Index extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      reRender: false,
    };
  }

  componentDidMount() {
    getLocaleLabelByCode('odoc').then(() => this.setState({ reRender: true }));
  }

  render() {
    return (
      <Provider ecId={`${this && this.props && this.props.ecId || ''}_Provider@a1fkg5`} {...stores}>
        <DocTemplate ecId={`${this && this.props && this.props.ecId || ''}_DocTemplate@f34so9`} />
      </Provider>
    );
  }
}

export default WeaTools.tryCatch(React, MyErrorHandler, { error: '' })(Index);
